/* SPDX-License-Identifier: GPL-2.0-or-later
 *
 *
 * Copyright (C) 2016-2021, LomboTech Co.Ltd.
 * Authors:
 *	lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#ifndef _CSP_CSC_H_
#define _CSP_CSC_H_

#include <linux/types.h>

#define __CSC_MODE(fmt, std, bit)	\
	(((fmt) & 0xF) | (((bit) & 0xF) << 4) | (((std) & 0xFF) << 8))

/* Color space conversion format */
/* keep same as dpu_csc_mode_t */
enum {
	CSC_BYPASS = 0,
	CSC_RGB2YUV,
	CSC_YUV2RGB,
};

/* color space */
enum {
	CSC_BT601L = 0, /* ITU BT.601l or bypass*/
	CSC_BT601F, /* ITU BT.601F or 0/2/1*/
	CSC_BT709L, /* ITU BT.709L or 1/2/0 */
	CSC_BT709F, /* ITU BT.709F or 2/0/1*/
	CSC_MAX,
};

/* precision bit */
enum {
	CSC_PRECISION_BIT12, /* bit12 as default */
	CSC_PRECISION_BIT10,
};

/* csc mode */
enum {
	CSC_RGB2YUV_BT601L_BIT12 =
		__CSC_MODE(CSC_RGB2YUV, CSC_BT601L, CSC_PRECISION_BIT12),
	CSC_RGB2YUV_BT601F_BIT12 =
		__CSC_MODE(CSC_RGB2YUV, CSC_BT601F, CSC_PRECISION_BIT12),
	CSC_RGB2YUV_BT709L_BIT12 =
		__CSC_MODE(CSC_RGB2YUV, CSC_BT709L, CSC_PRECISION_BIT12),
	CSC_RGB2YUV_BT709F_BIT12 =
		__CSC_MODE(CSC_RGB2YUV, CSC_BT709F, CSC_PRECISION_BIT12),

	CSC_YUV2RGB_BT601F_BIT12 =
		__CSC_MODE(CSC_YUV2RGB, CSC_BT601F, CSC_PRECISION_BIT12),
	CSC_YUV2RGB_BT601L_BIT12 =
		__CSC_MODE(CSC_YUV2RGB, CSC_BT601L, CSC_PRECISION_BIT12),
	CSC_YUV2RGB_BT709L_BIT12 =
		__CSC_MODE(CSC_YUV2RGB, CSC_BT709L, CSC_PRECISION_BIT12),
	CSC_YUV2RGB_BT709F_BIT12 =
		__CSC_MODE(CSC_YUV2RGB, CSC_BT709F, CSC_PRECISION_BIT12),

	CSC_BYPASS_012 = __CSC_MODE(CSC_BYPASS, 0, 0),
	CSC_BYPASS_021 = __CSC_MODE(CSC_BYPASS, 1, 0),
	CSC_BYPASS_120 = __CSC_MODE(CSC_BYPASS, 2, 0),
	CSC_BYPASS_201 = __CSC_MODE(CSC_BYPASS, 3, 0),
	CSC_BYPASS_210 = __CSC_MODE(CSC_BYPASS, 4, 0),
};

void *csc_get_coef(u32 mode);

#endif /* _CSP_CSC_H_ */
